package com.inforich.projectManage.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inforich.common.enums.StageEnum;
import com.inforich.projectManage.domain.ProjectRubbishDetail;
import com.inforich.projectManage.domain.StageRubbishDetail;
import com.inforich.projectManage.mapper.ProjectRubbishDetailMapper;
import com.inforich.projectManage.service.IProjectRubbishDetailService;

import cn.hutool.core.collection.CollUtil;

/**
 * 项目垃圾明细Service业务层处理
 *
 * @author hjm
 * @date 2022-10-30
 */
@Service
public class ProjectRubbishDetailServiceImpl extends
    ServiceImpl<ProjectRubbishDetailMapper, ProjectRubbishDetail> implements
    IProjectRubbishDetailService {

  @Override
  public Page<ProjectRubbishDetail> pageProjectRubbishDetail(Page<ProjectRubbishDetail> page,
      Map<String, Object> map) {
    return baseMapper.pageProjectRubbishDetail(page, map);
  }

  @Override
  public List<ProjectRubbishDetail> listProjectRubbishDetail(Map<String, Object> map) {
    return baseMapper.listProjectRubbishDetail(map);
  }

  @Override
  public List<ProjectRubbishDetail> listProjectRubbishDetailByProjectId(String projectId) {
    return baseMapper.listProjectRubbishDetailByProjectId(projectId);
  }

  @Override
  public void removeByProjectId(String projectId) {
    remove(new LambdaQueryWrapper<ProjectRubbishDetail>()
        .eq(ProjectRubbishDetail::getProjectId, projectId));
  }

  @Override
  public void saveDetail(List<ProjectRubbishDetail> detailList, String projectId,
      StageEnum stageEnum) {
    remove(new LambdaQueryWrapper<ProjectRubbishDetail>()
        .eq(ProjectRubbishDetail::getProjectId, projectId)
        .eq(ProjectRubbishDetail::getRubbishStage, stageEnum.getDbData()));
    if (CollUtil.isEmpty(detailList)) {
      return;
    }
    detailList.forEach(d -> {
      d.setProjectId(projectId);
      d.setRubbishStage(stageEnum.getDbData());
    });
    saveBatch(detailList);
  }

  @Override
  public List<StageRubbishDetail> listStageRubbishDetail(String projectId, String stage) {
    return baseMapper.listStageRubbishDetail(projectId,stage);
  }

}
